/*++

Copyright (c) Microsoft Corporation. 
 
This source code is subject to terms and conditions of the Microsoft
Public License. A copy of the license can be found in the License.txt
file at the root of this distribution. By using this source code in 
any fashion, you are agreeing to be bound by the terms of the Microsoft
Public License.
 
You must not remove this notice, or any other, from this software.

Module Name:

    SensorBaseDriver.h

Abstract:

    This module contains the definitions for the code that parses the data issued by the sensor.
--*/

#pragma once
#include <stdio.h>
#include <tchar.h>

// This driver is entirely user-mode
__user_code;

#include <atlbase.h>
#include <atlcom.h>
#include <atlcoll.h>
#include <atlstr.h>
#include <strsafe.h>

// Added below to try and resolve compiler error in RS232Target.h
#include <wudfddi.h>

// We need a class extension pointer to handle events
#include <sensorsclassextension.h>

class RS232Connection;
class RS232Target;
class WpdObjectProperties;

typedef struct tagSENSOR_INFO{
    unsigned char   deviceID;
    unsigned short  dataLength;         
} SENSOR_INFO;

class SensorBaseDriver :
    public IUnknown
{
public:
    SensorBaseDriver();
    virtual ~SensorBaseDriver();
    HRESULT ProcessReadData(__in_bcount(cbData) BYTE* pData, size_t cbData);
    RS232Target* GetRS232Target();
    HRESULT Initialize(IWDFDevice* pDevice);
    void Uninitialize();

public: // IUnknown
    ULONG __stdcall AddRef();

    __drv_at(this, __drv_freesMem(Mem)) 
    ULONG __stdcall Release();

    HRESULT __stdcall QueryInterface(REFIID riid, void** ppv);

private:

    HRESULT PostSensorReadingEvent(LPCWSTR wszDeviceID);
   
public:
        
    enum SensorType{
      UNKNOWN,  // Unknown
      COMPASS,  // Compass
      SENSIRON, // Temp/humidity sensor 
      FLEX,     // Flexiforce sensor
      PING,     // Ultrasonic ping 
      PIR,      // Passive infrared
      MEMSIC,   // 2-axis accelerometer 
      QTI,      // Light sensor
      PIEZO,    // Vibration Sensor 
      HITACHI,  // 3-axis accelerometer
    };

    SensorType   m_SensorType;  // enum value specifying sensor type

private:

    ULONG                          m_cRef;
    RS232Connection*               m_pConnection;
    IWDFDevice*                    m_pWDFDevice;

public:
    RS232Target*                   m_pTarget;

    WpdObjectProperties*           m_pObjectProperties;

    // Required to post events
    CComPtr<ISensorClassExtension> m_spSensorCXT;

    // We use this identifier when posting the 
    // state-change event in the RS232Target object
    LPWSTR                         m_wszDeviceID;

    // The timer-proc in the RS232Target class consumes this value
    DWORD                          m_Interval; 

};


